<?php

namespace App\Transformers;

use League\Fractal\TransformerAbstract;
use App\Models\Period;
use App\Models\StaffPeriodFee;

/**
 * Class PeriodTransformer.
 *
 * @package namespace App\Transformers;
 */
class PeriodTransformer extends TransformerAbstract
{
    /**
     * Transform the Period entity.
     *
     * @param \App\Models\Period $model
     *
     * @return array
     */
    public function transform(Period $model)
    {
        return [
            'id'         => (int) $model->id,
            'has_fee' => (bool) StaffPeriodFee::where('period_id', $model->id)->exists(),
            'name' => $model->name,
            'year' => $model->year,
            'month' => $model->month,
            'start_date' => $model->start_date,
            'end_date' => $model->end_date,
            'status' => $model->status,
            'created_at' => $model->created_at->format('Y-m-d H:i:s'),
            'updated_at' => $model->updated_at->format('Y-m-d H:i:s')
        ];
    }
}
